<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/static/common/default.jsp"%>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	</head>
	
	<body>
		<div class="breadcrumbs" id="breadcrumbs">
	
			<ul class="breadcrumb">
				<li><i class="icon-home home-icon"></i> <a href="#">首页</a></li>
				<li>班级管理</li>
				<li class="active">修改</li>
			</ul>
			
		</div>
		
		<div class="page-content">
			<div class="page-header">
				<h1>班级管理
					<small>
					<i class="icon-double-angle-right"></i>
					修改				
					</small>					
				</h1>							 							
			</div> 
			<div class="row">
				<div class="col-xs-12">
					<form class="form-horizontal" onsubmit="return sysInfoAdd();" role="form" id="schoolForm" name="schoolForm" method="post">
						
						<div class="form-group" >
							<label class="col-sm-3 control-label no-padding-right" for="form-field-1">班级名称</label>
							<div class="col-sm-9">
								<input type="text" id="name"  name="name" value="${info.name}" placeholder="班级名称" required class="col-xs-10 col-sm-5" size="50" />
							</div>
						</div>
						<div class="form-group" >
							<label class="col-sm-3 control-label no-padding-right" for="form-field-1">学校</label>
							<div class="col-sm-9">
							<select id="schoolId" name ="schoolId" onchange="javascript:changeSchool();">
								<option value="">请选择</option>
							</select>
							</div>
						</div>
						<div class="form-group" >
							<label class="col-sm-3 control-label no-padding-right" for="form-field-1">年级</label>
							<div class="col-sm-9">
							<select id="gradeId" name ="gradeId">
								<option value="">请选择</option>
							</select>
							</div>
						</div>
						<input type="hidden" id="id"  name="id" value="${info.id}"/>
						
						<div class="clearfix form-actions">
							<div class="col-md-offset-3 col-md-9">
								<button class="btn btn-info" type="submit">
									<i class="icon-ok bigger-110"></i>提交
								</button>
							</div>
						</div>
						
					</form>		
				</div>
							
			</div>
		</div>
		
		<script type="text/javascript">
			function sysInfoAdd() {
					var datastr = new Object();
	    			datastr.name = $('#name').val();
	    			datastr.schoolId = $('#schoolId').val();
	    			datastr.gradeId = $('#gradeId').val();
	    			datastr.id = $('#id').val();
					var result = true;
					$.ajax({
    		        async: true,
    		        type:"POST",
    		        data:JSON.stringify(datastr),
    		        url: "${ctx}/sys/tclass/update",
    		        dataType: "json",
    		        headers : {  
                        'Content-Type' : 'application/json;charset=utf-8'  
                    },
	                success : function(data) {
	                		if (data != undefined && data.status != undefined
	                				&& data.status.trim() == '0') {
	                			result = true;
	                			alert("保存成功！");
	                			window.location.href = "${ctx}/sys/tclass/list";
	                		} else {
	                			result = false;
	                			alert(data.error);
	                		}
	                	},
	    			},"json");
				return false;
			}
			
			 $(function(){
				 var schoolId = ${info.schoolId};
				 $.ajax({
				        async: true,
				        type:"POST",
				        data:null,
				        url: "${ctx}/sys/tschool/listall",
				        dataType: "json",
				        success: function (data) {
				    	    if("success" == data.result){//成功
								if(data.list.length>0){
									for(var a=0;a<data.list.length;a++){
										if(schoolId == data.list[a].id ){
											$("#schoolId").prepend("<option selected = 'selected' value='"+data.list[a].id+"'>"+data.list[a].name+"</option>");
										}else{
											$("#schoolId").prepend("<option value='"+data.list[a].id+"'>"+data.list[a].name+"</option>");
										}
										
									}
								}else{
									
								}
				    	    }else{//失败
				    	    	alert("学校加载失败");
				    	    }
				        }
					},"json");
				 var gradeId = ${info.gradeId};
				 var obj = new Object();
				 obj.schoolId= schoolId;
				 $.ajax({
				        async: true,
				        type:"POST",
				        data:obj,
				        url: "${ctx}/sys/tgrade/findgradeBySchoolId",
				        dataType: "json",
				        success: function (data) {
				    	    if("success" == data.result){//成功
								if(data.list.length>0){
									for(var a=0;a<data.list.length;a++){
										if(gradeId == data.list[a].id ){
											$("#gradeId").prepend("<option selected = 'selected' value='"+data.list[a].id+"'>"+data.list[a].name+"</option>");
										}else{
											$("#gradeId").prepend("<option value='"+data.list[a].id+"'>"+data.list[a].name+"</option>");
										}
										
									}
								}
				    	    }else{//失败
				    	    	alert("年级加载失败");
				    	    }
				        }
					},"json");
			 });
			 
			 function changeSchool(){
					var schoolId =$("#schoolId").val();
					clearGrade();
					var obj = new Object();
					obj.schoolId= schoolId;
					if(schoolId!=null && schoolId!=""){
						$.ajax({
					        async: true,
					        type:"POST",
					        data:obj,
					        url: "${ctx}/sys/tgrade/findgradeBySchoolId",
					        dataType: "json",
					        success: function (data) {
					    	    if("success" == data.result){//成功
									if(data.list.length>0){
										for(var a=0;a<data.list.length;a++){
											$("#gradeId").append("<option value='"+data.list[a].id+"'>"+data.list[a].name+"</option>");
										}
									}else{
									}
					    	    }else{//失败
					    	    	alert("年级加载失败");
					    	    }
					        }
						},"json");
					}
				}
				function clearGrade(){
					$("#gradeId").val("");
					$("#gradeId").html("");
					$("#gradeId").append("<option  value=''>请选择</option>");
				}
			
			 
		</script>
	</body>


</html>